<!DOCTYPE html>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="/tld/authority.tld" prefix="authority" %>
<%@ taglib uri="/tld/token.tld" prefix="token" %>
<div class="pop-background">
    <div class="col-md-4">
        <div class="popup popup5 popup-small x-4-move">
            <div class="panel-heading">
                <div class="panel-btns">
                    <a class="panel-close btn-4-hide">×</a>
                </div>
                <h3 class="panel-title">${empty brand.id ? '新增' : '修改'}</h3>
            </div>
            <div class="panel-add-to">
                <div class="row">
                    <form class="data">
                        <token:token/>
                        <input type="hidden" name="id" value="${brand.id}">
                        <input type="hidden" name="logo" value="${brand.logo}">
                        <div class="panel-body panel-body-ws">
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">
                                        品牌名称：</label>

                                    <div class="col-sm-6">
                                        <label class="col-sm-3 control-label">${brand.name}</label>
                                        <input type="hidden" class="form-control" name="name" value="${brand.name}"
                                               readonly>
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">
                                        品牌编码：</label>

                                    <div class="col-sm-6">
                                        <label class="col-sm-3 control-label">${brand.identifier}</label>
                                        <input type="hidden" class="form-control" name="identifier"
                                               value="${brand.identifier}"/>
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">
                                        公司名称：</label>

                                    <div class="col-sm-6">
                                        <label class="col-sm-3 control-label">${brand.companyName}</label>
                                        <input type="hidden" class="form-control" name="companyName"
                                               value="${brand.companyName}">
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-6 hidden">
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">主要行业：</label>

                                    <div class="col-sm-6">

                                        <c:forEach items="${industryList}" var="ind" varStatus="status">
                                            <c:set value="0" var="hasIn" scope="page"/>
                                            <c:forEach items="${brand.industryList}" var="one">
                                                <c:if test="${one.id == ind.id}">

                                                    <c:set value="1" var="hasIn" scope="page"/>


                                                </c:if>
                                            </c:forEach>

                                            <input type="checkbox" name="industryIds" value="${ind.id}"
                                            <c:if test="${hasIn == 1}">

                                                   checked


                                            </c:if>
                                            >${ind.name}
                                        </c:forEach>
                                    </div>
                                </div>
                            </div>

                            <div class="col-md-6">
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">价格保护品牌：</label>

                                    <div class="col-sm-6">
                                        <input type="checkbox"
                                               class="brand-protection" ${1 eq brand.protection?"checked":""} />
                                        <input type="hidden" id="protection" name="protection"
                                               value="${empty brand.protection?0:brand.protection}"/>
                                    </div>
                                </div>
                            </div>

                            <div class="col-md-6">
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">是否禁用：</label>

                                    <div class="col-sm-6">
                                        <input type="checkbox" class="brand-disabled" ${brand.disabled?"checked":""} />
                                        <input type="hidden" id="disabled" name="disabled"
                                               value="${brand.disabled?1:0}"/>
                                    </div>
                                </div>
                            </div>

                            <%--<div class="col-md-6">
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">排序值：</label>

                                    <div class="col-sm-6">
                                        <input type="text" class="form-control" name="seq" value="${brand.seq}">
                                    </div>
                                </div>
                            </div>--%>
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">LOGO：</label>
                                    <span class="form-group-span">
										<a class="add-pictures btn-4-fup"
                                           style="display: ${empty brand.logo ? 'inline-block;' : 'none;'}"><span><i
                                                class="icon icon-tianjia"></i></span></a>
                                        <c:if test="${!empty brand.logo}">
                                            <a class="add-pictures ex"><i class="icon icon-cha color-red"></i><img
                                                    src="${brand.logo}"></a>
                                        </c:if>
                                    </span>
                                </div>
                            </div>

                            <%--<div class="col-md-6">
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">详情介绍：</label>

                                    <div class="col-sm-6">
                                        &lt;%&ndash; <script id="editor" type="text/plain" style="width:700px;height:100px;"></script> &ndash;%&gt;
                                        <textarea name="content" id="content" cols="60" rows="4">${brand.content}</textarea>

                                    </div>
                                </div>
                            </div>--%>

                        </div>
                    </form>
                </div>

                <div class="btn-group2-s">
                    <div class="panel-body panel-body2">
                        <div class="btn-group2 left">
                            <authority:authority url="/brand/add,/brand/modify">
                                <button type="button" class="btn btn-primary btn-4-save">保存</button>
                            </authority:authority>
                            <button type="button" class="btn btn-default btn-4-hide">取消</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <form method="post" enctype="multipart/form-data" style="display: none;">
        <input class="cursor-pointer input-4-fup" type="file" name="file"/>
    </form>

    <script>
        $(document).ready(function () {

            $('#pop-wrapper select').select0();

            $('#pop-wrapper .x-4-move').dragging({
                move: 'both',
                randomPosition: false,
                handler: '.panel-heading'
            });

            $('#pop-wrapper .brand-protection').off('click').on('click', function () {
                if ($(this).prop('checked')) {
                    $('#protection').val('1');
                } else {
                    $('#protection').val('0');
                }
            });
            $('#pop-wrapper .brand-disabled').off('click').on('click', function () {
                if ($(this).prop('checked')) {
                    $('#disabled').val('1');
                } else {
                    $('#disabled').val('0');
                }
            });

            $('#pop-wrapper .btn-4-save').off('click').on('click', function () {
                var id = $('#pop-wrapper input[name=id]').val();
                var url = 'brand/add.htm';
                if (id) {
                    url = 'brand/modify.htm';
                }

                ajaxSubmitResponseJSON({
                    url: url,
                    method: 'POST',
                    data: $('#pop-wrapper form.data').serialize(),
                    success: function (data) {
                        if (data.status == 0) {
                            closeLayer();
                            $('#data-wrapper .btn-4-query').trigger('click');
                        }
                    }
                });
            });

            $('#pop-wrapper .btn-4-fup').off('click').on('click', function () {
                $('#pop-wrapper .input-4-fup').trigger('click');
            });

            $('#pop-wrapper .input-4-fup').off('change').on('change', function () {
                ajaxMultiSubmitResponseJSON({
                    url: 'fileUpload/upload.htm',
                    form: $(this).parent(),
                    success: function (data) {
                        if (data.status == 0) {
                            $('#pop-wrapper input[name=logo]').val(data.data);
                            var imgHtm = '<a class="add-pictures ex" ><i class="icon icon-cha color-red"></i><img src="' + data.data + '"></a>';
                            $('#pop-wrapper .btn-4-fup').hide();
                            $('#pop-wrapper .btn-4-fup').parent().find('a.ex').remove();
                            $('#pop-wrapper .btn-4-fup').parent().append(imgHtm);
                        }
                    }
                });
            });

            $(document).off('click', '#pop-wrapper a.ex').on('click', '#pop-wrapper a.ex', function () {
                $('#pop-wrapper input[name=logo]').val('');
                $('#pop-wrapper .btn-4-fup').parent().find('a.ex').remove();
                $('#pop-wrapper .btn-4-fup').show();
                var id = $('#pop-wrapper input[name=id]').val();
                if (!id) {
                    var src = $(this).find('img').attr('src');
                    ajaxSubmitResponseJSON({
                        url: 'fileUpload/delete.htm',
                        data: 'file=' + src
                    });
                }
            });

        });
    </script>
</div>